package pool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/*
周期性线程池
 */
public class ThreadPoolDemo5 {
  public static void main(String[] args) {
    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);
    try {
      for (int i = 0; i < 10; i++) {
        executorService.schedule(new Runnable() {
          @Override
          public void run() {
            System.out.println(Thread.currentThread().getName());
          }
        },10, TimeUnit.SECONDS);
      }
    }catch (Exception e){
      e.printStackTrace();
    }finally {
      executorService.shutdown();
    }
  }
}
